#网络编程
from urllib import request,parse,robotparser
#get请求
'''
url = 'http://baidu.com'
headers = {"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"}
request_obj= request.Request(url=url,headers=headers,method='GET')
response = request.urlopen(request_obj)
print(response.read().decode('utf-8'))
'''
#post请求

param = {"key":"helloword"}
param_str = parse.urlencode(param)
param_datas = bytes(param_str,encoding='utf-8')
headers = {"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"}
url  = 'http://httpbin.org/post'
request_obj = request.Request(url=url,headers=headers,data=param_datas,method="POST")
response = request.urlopen(request_obj)

print(response.read().decode('utf8'))
print(response.status)
print(response.getheaders())
print(response.getheader('Date'))

